package com.gxuwz.core.util;

import java.io.OutputStream;
import java.util.List;

import org.apache.poi.hssf.record.formula.functions.T;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;

import com.gxuwz.PangGuangyao.business.entity.SysRepair;

public class ExcelUtil {
	public static HSSFWorkbook toExcel( String headers[] , List<SysRepair> list, OutputStream out) {

		
		HSSFWorkbook wwb = null ;

	 	try {
			 wwb = new HSSFWorkbook();

			// 创建工作簿
			HSSFSheet sheet = wwb.createSheet("教学档案");
			// 设置行宽
						sheet.setColumnWidth(0, 3500);
						sheet.setColumnWidth(1, 3500);
						sheet.setColumnWidth(2,3500);
						sheet.setColumnWidth(3,3500);
			HSSFRow row = null;
			// 创建表头
			row = sheet.createRow(0);
			for (int i = 0; i < headers.length; i++) {
				row.createCell(i).setCellValue(headers[i]);
			}

			// 添加内容
			SysRepair sysRepair = null;
			for (int i = 0; i < list.size(); i++) {
				sysRepair=  (SysRepair) list.get(i);
				row = sheet.createRow(i + 1);
                String value[]=new String [4];

               row.createCell(0).setCellValue(list.get(i).getMd_id());
                row.createCell(1).setCellValue(list.get(i).getMd_cost());
                row.createCell(2).setCellValue(list.get(i).getMd_reason());
                row.createCell(3).setCellValue(list.get(i).getMdstate());

			}
			 HSSFFont font = wwb.createFont();   
			 font.setFontName("宋体");   
			  font.setFontHeightInPoints((short) 10);  
			HSSFDataFormat format = wwb.createDataFormat();
			// 格式化数据
			HSSFCellStyle style = wwb.createCellStyle();
		
			style.setFont(font);   
		    style.setAlignment(HSSFCellStyle.ALIGN_LEFT);// 左右居中   
			 style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);// 上下居中   
			 style.setWrapText(true);   
		   style.setLeftBorderColor(HSSFColor.BLACK.index);   
			  style.setBorderLeft((short) 1);   
			 style.setRightBorderColor(HSSFColor.BLACK.index);   
			    style.setBorderRight((short) 1);   
		   style.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体   
			   style.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色．   
			   style.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色．   

			
			   
			

			//sheet.autoSizeColumn(1);
			//sheet.autoSizeColumn(2);

			wwb.write(out);

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return wwb;
	}

public static void  initValue(String value[], SysRepair sysRepair)
{
	sysRepair=new SysRepair();
	 value[0]=sysRepair.getMd_id();
	 value[0]=String.valueOf(sysRepair.getMd_cost());
	 value[0]=sysRepair.getMd_reason();
	 value[0]= String.valueOf(sysRepair.getMdstate()) ;
	 
}
	
}
